//
//  RefreshCarStatus.m
//  carcareIOS
//
//  Created by ileo on 15/9/5.
//  Copyright (c) 2015年 baozun. All rights reserved.
//

#import "RefreshCarStatus.h"
#import "NetCar.h"
#import "NetDrives.h"
#import "CalendarMgr.h"
#import "NetHome.h"

@implementation RefreshCarStatus

IMP_SINGLETON

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.timeInterval = 3600;
        __weak __typeof(self) wself = self;
        self.Refresh = ^(){
            [[NetCar getCarSituation] requestSuccess:^(id JSON) {
                wself.remainFuel = [JSON[@"remainFuel"] floatValue];
                wself.carMiles = [JSON[@"carMiles"] floatValue];
//                wself.carMiles = 10000;

                wself.enduranceMileage = [JSON[@"enduranceMileage"] floatValue];
                wself.voltage = [JSON[@"voltage"] floatValue];
                if (wself.RefreshCallBack) {
                    wself.RefreshCallBack(JSON);
                }
            }];
            [[NetDrives drivesWithDate:CALENDARMGR.currentDay] requestSuccess:^(id JSON) {
                wself.driveNums = ((NSArray *)JSON[@"travels"]).count;
                if (wself.RefreshCallBack) {
                    wself.RefreshCallBack(JSON);
                }
            }];
#warning 震动次数
            [[NetHome getNoticeWithHeadID:0 orEndID:0] requestSuccess:^(id JSON) {
                NSInteger shockTimes = 0;
                for (NSDictionary *dic in JSON[@"infolist"]) {
                    if ([dic[@"TYPE"] integerValue] == 12) {
                        shockTimes++;
                    }
                }
                wself.shockTims = shockTimes;
                if (wself.RefreshCallBack) {
                    wself.RefreshCallBack(JSON);
                }
            } failure:^(id JSON) {
                
            }];
            
        };
    }
    return self;
}

@end
